@extends("layouts.app")
@section('content')

<section class="content-header">
    <h1>
        派发京东券
    </h1>
    <ol class="breadcrumb">
        <li><a href="/dashboard"><i class="fa fa-dashboard"></i>家</a></li>
        <li class="active">派发京东券</li>
    </ol>
</section>
<section class="content-header">
    <div class="alert alert-success alert-dismissible" id="showmsg" style="display: none;">
        <button type="button" class="close" data-dismiss="alert" aria-hidden="true">×</button>
        <h4><i class="icon fa fa-check"></i> 发送状态!</h4>
        <ul>

        </ul>
    </div>
</section>
<section class="content">
    <div class='row text'>
        <div class='col-sm-12'>
            <div class="box">
                <div class="content">
                    <form action="" method="post">
                        {{ csrf_field()}}
                        <label for='tag'>输入格式：姓名|手机号,姓名|手机号</label>
                        <input type='hidden' name='select' value='users' id='users'>
                        <br>
                        <div>
                            <textarea id="text" name="text" rows="20" class="form-control" placeholder="请导入派发数据">{{ old('text') }}</textarea>
                            <div class="box-footer">
                            <input type="submit" value="派发" name="opsubmit" class="btn btn-primary"/>
                            </div>
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </div>
    <div class="row">
        <div class="col-xs-12">
            <div class="box">
                <div class="box-header with-border">
                    <h3 class="box-title">搜索</h3>
                    <div class="box-tools"></div>
                </div>
                <div class="box-body">
                    <div id="example2_wrapper" class="dataTables_wrapper form-inline dt-bootstrap">
                        <form class="form-inline" role="form" method="get" id="frmSearch">
                            <div class="form-group">
                                <select class="form-control type form-inline" name="issucced">
                                    <option value="">是否成功</option>
                                    <option value="1">成功</option>
                                    <option value="0">失败</option>
                                </select>
                            </div>&nbsp;
                            <input type="hidden" name="_token" value="{{ csrf_token() }}">
                            <input type="submit" class="btn  btn-success" value="搜索">&nbsp;
                        </form>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <div class="row">
        <div class="col-sm-12">
            <div class="box">
                <div class="box-header with-border box-danger">
                    <h3 class="box-title">短信列表</h3>
                </div>

                <!-- /.box-body -->
                <div class="box-body">
                    <div id="example2_wrapper" class="dataTables_wrapper form-inline dt-bootstrap">
                        <div class="row">
                            <div class="col-sm-6"></div>
                            <div class="col-sm-6"></div>
                        </div>
                        <div class="row">
                            <div class="col-sm-12">
                                <table id="example2" class="table table-bordered table-hover dataTable text-center" role="grid"
                                       aria-describedby="example2_info">
                                    <thead>
                                        <tr role="row">

                                            <th class="sorting col-sm-1" aria-controls="example2" rowspan="1"
                                                colspan="1"
                                                aria-label="Browser: activate to sort column ascending">
                                                姓名/手机号
                                            </th>

                                            <th class="sorting col-sm-2" aria-controls="example2" rowspan="1"
                                                colspan="1"
                                                aria-label="Platform(s): activate to sort column ascending">
                                                是否成功
                                            </th>
                                            <th class="sorting col-sm-2" aria-controls="example2" rowspan="1"
                                                colspan="1"
                                                aria-label="Engine version: activate to sort column ascending">
                                                短信内容
                                            </th>
                                            <th class="sorting col-sm-2" aria-controls="example2" rowspan="1"
                                                colspan="1"
                                                aria-label="Engine version: activate to sort column ascending">
                                                返回内容
                                            </th>
                                            <th class="sorting col-sm-2" aria-controls="example2" rowspan="1"
                                                colspan="1"
                                                aria-label="Engine version: activate to sort column ascending">
                                                派发时间
                                            </th>
                                        </tr>
                                    </thead>
                                    <tbody>
                                        @foreach($list as $value)
                                        <tr role="row" class="odd">

                                            <td>{{$value->params}}</td>
                                            <td>@if($value->issucced == '1')成功@else失败@endif</td>
                                            <td>{{$value->content}}</td>
                                            <td>{{$value->message}}</td>
                                            <td>{{$value->created_at}}</td>
                                        </tr>
                                        @endforeach
                                    </tbody>
                                </table>
                            </div>
                        </div>
                        @include("layouts.page",['paginator'=>$list])
                    </div>
                </div>
            </div>
        </div>
    </div>
</section>
<script type="text/javascript">
    var url_base = "{{env('URL_SUB', '')}}";
    function dopostcoupon(str){
        $.ajax({
            url: url_base+'/admin/hillclimb/dopostcoupon',
            type: 'POST',
            data: {str: str},
            dataType: 'json',
            async:false,
            headers: {
                'X-CSRF-TOKEN': $('input[name=_token]').val()
            },
            contentType: "application/x-www-form-urlencoded; charset=utf-8",
            error: function() {
                //alert('Error loading PHP document');
            },
            success: function(json) {
                $("#showmsg").find("ul").append("<li>"+str+"："+json.msg+"</li>");
            }
        });
    }
    $(function() {
        $("form").submit(function() {
            var send = confirm('确定要派发?');
            if (send == true) {
                var _text = $.trim($("#text").val()).replace(/\s/g,'');
                var data_text = _text.split(',');
                $("#showmsg").show();
                $.each(data_text, function(i,val){          
                    dopostcoupon(val);
                });
            }
            return false;
        });
    })
</script>
<script>
    $(function() {
        var search = location.search.substring(1);
        if (search) {
            try {
                var query = JSON.parse('{"' + decodeURIComponent(search).replace(/"/g, '\\"').replace(/&/g, '","').replace(/=/g, '":"') + '"}');

                $.each(query, function(k, v) {
                    $('[name=' + k + ']').val(v);
                });
            } catch (e) {
                console.log(e);
            }

        }
    })
</script>
<script src="{{env('URL_SUB', '')}}/bower_components/AdminLTE/plugins/iCheck/icheck.min.js"></script>
<script src="{{env('URL_SUB', '')}}/bower_components/AdminLTE/plugins/iCheck/icheck.js"></script>
@endsection
